﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Filter : System.Web.UI.UserControl
{
    DataTable dtb = new DataTable();
    string command;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            command = "select TenHang from hangxe";
            dtb = DataBase.GetDataTable(command);
            foreach (DataRow dtr in dtb.Rows)
            {
                cmbHangxe.Items.Add(dtr[0].ToString());
            }
        }
    }
    protected void cmbHangxe_SelectedIndexChanged(object sender, EventArgs e)
    {
        string hangxe = cmbHangxe.SelectedItem.Text;
        command = string.Format(@"
                                SELECT Model
                                FROM model AS a
                                INNER JOIN hangxe AS b ON a.MaHangXe=b.MaHangXe
                                WHERE b.TenHang='{0}'
                                ", hangxe);

        cmbModel.Items.Clear();
        cmbModel.Items.Add("Tất cả");
        DataTable dtb1 = DataBase.GetDataTable(command);
        foreach (DataRow dtr in dtb1.Rows)
        {
            cmbModel.Items.Add(dtr[0].ToString());
        }
    }
    protected void btnTim_Click(object sender, EventArgs e)
    {
        string TenXe = txtTenXe.Text;
        string HangXe = cmbHangxe.Text;
        string Model = cmbModel.Text;
        string TinhTrang = cmbTinhTrang.Text;
        string NamSX = cmbYear.Text;
        Response.Redirect("TimKiem.aspx?TenXe=" + TenXe + "&HangXe=" + HangXe + "&Model=" + Model + "&TinhTrang=" + TinhTrang + "&NamSanXuat=" + NamSX);

    }
}
